<!DOCTYPE html>
<html lang="en">
<head>
    <title>商品详情</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css" /><!-- bootstrap -->
    <script type="text/javascript" src="/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="/jquery-validation/jquery.validate.min.js"></script> <!-- jquery-validator -->
    <script type="text/javascript" src="/jquery-validation/localization/messages_zh.min.js"></script>
    <script type="text/javascript" src="/layer/layer.js"></script><!-- layer -->
    <script type="text/javascript" src="/js/md5.min.js"></script><!-- md5.js -->
    <script type="text/javascript" src="/js/common.js"></script><!-- common.js -->
</head>
<body>

<div class="panel panel-default">
    <div class="panel-heading">秒杀商品详情</div>
    <div class="panel-body">
        <#if !user??>
            <span> 您还没有登录，请登陆后再操作<br/></span>
        </#if>
        <span>没有收货地址的提示。。。</span>
    </div>
    <table class="table">
        <tr>
            <td>商品名称</td>
            <td colspan="3">${good.goodName}</td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td colspan="3"><img src="${good.goodImg}" width="200" height="200" /></td>
        </tr>
        <tr>
            <td>秒杀开始时间</td>
            <td >${good.startDate?string('yyyy-MM-dd HH:mm:ss')}</td>
            <td id="seckillTip"></td>
            <td>
                <form id="seckillForm" method="post" action="/seckill/do_seckill">
                    <button class="btn btn-primary btn-block" type="submit" id="buyButton">立即秒杀</button>
                    <input type="hidden" name="goodId" value="${good.id}" />
                </form>
            </td>
        </tr>
        <tr>
            <td>商品原价</td>
            <td colspan="3">${good.goodPrice}</td>
        </tr>
        <tr>
            <td>秒杀价</td>
            <td colspan="3">${good.seckillPrice}</td>
        </tr>
        <tr>
            <td>库存数量</td>
            <td colspan="3">${good.stockCount}</td>
        </tr>
    </table>
</div>
<script>
    var startDate = new Date("${good.startDate?string('yyyy-MM-dd HH:mm:ss')}");
    var endDate = new Date("${good.endDate?string('yyyy-MM-dd HH:mm:ss')}");
    var now = new Date();
    console.log(startDate);
    //距离开始秒杀的剩余时间 如果开始时间大于现在时间 则还未开始秒杀活动
    var startRemainSeconds = (startDate.getTime() - now.getTime())/1000;
    console.log(startRemainSeconds);
    //秒杀活动距离结束还有多少时间 结束时间减去当前时间
    var endRemainSeconds = (endDate.getTime() - now.getTime())/1000;
    $(function () {
        show();
        setInterval(show,1000);
    });
    function show() {
        startRemainSeconds--;
        endRemainSeconds--;
        if(startRemainSeconds > 0){
            //秒杀未开始  开始时间减当前时间还有剩余
            $("#seckillTip").html("秒杀倒计时: "+parseInt(startRemainSeconds)+"秒");
            $("#buyButton").prop("disabled",true);
        }else if (endRemainSeconds > 0){
            $("#seckillTip").html("秒杀中");
            $("#buyButton").prop("disabled",false);
        }else{
            $("#seckillTip").html("秒杀已结束");
            $("#buyButton").prop("disabled",true);
        }
    }

</script>
</body>
</html>
